<template>
	<view style="padding-bottom: 80upx;">
		<view class="flex align-center padding-lr">
			<view class="u-m-r-10">
				<image :src="avatar" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;"
					@click="goNav('/pages/my/userinfo')"></image>

			</view>
			<view class=" u-m-l-10 text-white margin-left-sm" v-if="!isLogin">
				<view class="" @click="goNav('/pages/my/userinfo')">{{userName}}</view>
				<view class="" v-if="XCXIsSelect != '否'">
					<view v-if="Qe == 0" class="round u-font-12" @click.stop="goNav('/my/renzheng/index')"
						style="color: #666666;font-weight: 400;">
						未入驻
					</view>
					<view v-else-if="Qe == 1" class="round u-font-12" style="color: #666666;font-weight: 400;"
						@click.stop="goNav('/my/renzheng/index')">
						审核中
					</view>
					<view v-else-if="Qe == 2" class="round u-font-12" style="color: #666666;font-weight: 400;"
						@click.stop="goNav('/my/renzheng/index')">
						已入驻
					</view>
					<view v-else-if="Qe == 3" class="round u-font-12" style="color: #666666;font-weight: 400;"
						@click.stop="goNav('/my/renzheng/index')">
						已拒绝
					</view>
				</view>
			</view>
			<view v-else class="text-xl u-p-l-20 text-bold" @click="goLogin('/pages/public/login')">
				登录
			</view>
		</view>
		<view class="flex align-center padding-left">
			<image src="../../static/images/data.png" style="width: 26upx;height: 26upx;"></image>
			<view class="margin-left-xs flex align-center" style="color: #999999;">
				<view @click="bindData(1)">{{startTime?startTime:'开始时间'}}</view>
				至
				<view @click="bindData(2)">{{endTime?endTime:'结束时间'}}</view>
			</view>
		</view>
		<view class="flex align-center box justify-between text-center">
			<view class="">
				￥<text class="text-bold text-xl">{{sumOrdersMoney?sumOrdersMoney:'0'}}</text>
				<view>总收益</view>
			</view>
			<view class="">
				<text class="text-bold text-xl">{{sumOrdersCount?sumOrdersCount:'0'}}</text>
				<view>总销量</view>
			</view>
			<view class="">
				<text class="text-bold text-xl">{{sumOrdersScore?sumOrdersScore:'0'}}</text>
				<view>用户评价</view>
			</view>
			<view class="">
				<text class="text-bold text-xl">{{shangCount+ xiaCount}}</text>
				<view>服务发布</view>
			</view>
		</view>
		<view class="padding">
			<view class="text-bold text-lg margin-bottom-sm">订单数据</view>
			<view class="orderbox ">
				<view class="">
					￥<text class="text-bold text-xl">{{ordersMoney?ordersMoney:'0'}}</text>
					<view class="margin-top-xs">订单收入</view>
				</view>
				<view class="">
					<text class="text-bold text-xl">{{ordersCount?ordersCount:'0'}}</text>
					<view class="margin-top-xs">总订单数</view>
				</view>
				<view class="">
					￥<text class="text-bold text-xl">{{refundMoney?refundMoney:'0'}}</text>
					<view class="margin-top-xs">取消订单金额</view>
				</view>
				<!-- <view class="">
					<text class="text-bold text-xl">{{userBrowseCount?userBrowseCount:'0'}}</text>
					<view class="margin-top-xs">访客人数</view>
				</view> -->
			</view>
		</view>
		<view style="padding: 0upx 30upx;">
			<view class="text-bold text-lg margin-bottom-sm flex justify-between">
				<view>订单管理</view>
				<view @click="goDetail(1)">
					<text style="color: #666666;font-size: 26upx;margin-right: 10upx;">查看全部</text>
					<image src="../../static/images/back.png" style="width: 12upx;height: 20upx;"></image>
				</view>
			</view>
			<view class="orderbox ">
				<!-- <view class="">
							<text class="text-bold text-xl">{{countOrderIng}}</text>
							<view class="margin-top-xs">待接单</view>
						</view> -->
				<view class="">
					<text class="text-bold text-xl">{{ ordersUnderwayCount?ordersUnderwayCount:'0'}}</text>
					<view class="margin-top-xs">待完成</view>
				</view>
				<view class="">
					<text class="text-bold text-xl">{{ordersAccomplishCount?ordersAccomplishCount:'0'}}</text>
					<view class="margin-top-xs">已完成</view>
				</view>
				<view class="">
					<text class="text-bold text-xl">{{commentCount?commentCount:'0'}}</text>
					<view class="margin-top-xs">已评价</view>
				</view>
			</view>
		</view>
		<view class="padding">
			<view class="text-bold text-lg margin-bottom-sm flex justify-between">
				<view>服务上架</view>
				<view @click="goDetail(4)">
					<text style="color: #666666;font-size: 26upx;margin-right: 10upx;">查看全部</text>
					<image src="../../static/images/back.png" style="width: 12upx;height: 20upx;"></image>
				</view>
			</view>
			<view class="orderbox ">
				<view class="">
					<text class="text-bold text-xl">{{shangCount?shangCount:'0'}}</text>
					<view class="margin-top-sm">上架中</view>
				</view>
				<view class="">
					<text class="text-bold text-xl">{{ xiaCount? xiaCount:'0'}}</text>
					<view class="margin-top-sm">已下架</view>
				</view>
				<view @click="bindFb()">
					<image src="../../static/images/index/add.png" style="width: 46upx;height: 46upx;"></image>
					<view class="margin-top-xs">添加服务</view>
				</view>

			</view>
		</view>

		<view style="padding: 0upx 30upx;" v-if="isAuthentication==2">
			<view class="text-bold text-lg margin-bottom-sm flex justify-between">
				<view>员工管理</view>
				<view @click="goDetail(3)">
					<text style="color: #666666;font-size: 26upx;margin-right: 10upx;">查看全部</text>
					<image src="../../static/images/back.png" style="width: 12upx;height: 20upx;"></image>
				</view>
			</view>
			<view class="orderbox ">
				<view class="">
					<text class="text-bold text-xl">{{ money?money:'0'}}</text>
					<view class="margin-top-xs">派单金额</view>
				</view>
				<view class="">
					<text class="text-bold text-xl">{{counts?counts:'0'}}</text>
					<view class="margin-top-xs">派单数量</view>
				</view>
				<view class="">

				</view>
			</view>
		</view>

		<view class="padding-lr margin-top">
			<view class="text-bold text-lg margin-bottom-sm flex justify-between">
				<view>今日订单</view>
				<view @click="goDetail(2)">
					<text style="color: #666666;font-size: 26upx;margin-right: 10upx;">查看全部</text>
					<image src="../../static/images/back.png" style="width: 12upx;height: 20upx;"></image>
				</view>
			</view>
			<view class="flex">
				<view class="flex-sub text-center orderbox1" v-for="(item,index) in order" :key="index"
					:class="orderIndex==index?'active':''" @click="orderChange(index)">
					{{item.name}}
				</view>
			</view>
			<view class="tadyOrder" v-for="(item,index) in orderlist" :key="index" v-if="orderIndex==0"
				@click="goDetails(item)">
				<view class="tadyOrder-left">
					<view class="tadyOrder-left-t">今日</view>
					<view class="tadyOrder-left-b">{{item.startTime}}</view>
				</view>
				<view class="tadyOrder-right">
					<view class="tadyOrder-right-t margin-top">{{item.myLevel}}</view>
					<view class="tadyOrder-right-b" @tap.stop="bindGps(item.latitude,item.longitude,item.detailsAddress)">
						<u-icon name="map-fill" color="#0175FE" size="28"></u-icon>
						<span style="margin-left: 5rpx;">{{item.city}}{{item.district}}{{item.detailsAddress}}</span>
					</view>
				</view>
			</view>
			<view class="tadyOrder" v-for="(item,index) in orderlist" :key="index" v-if="orderIndex==1"
				@click="goDetails(item)">
				<view class="tadyOrder-left">
					<view class="tadyOrder-left-t margin-top">今日</view>
					<view class="tadyOrder-left-b">{{item.deliveryTime}}</view>
				</view>
				<view class="tadyOrder-right margin-top-xs">
					<view class="tadyOrder-right-t margin-top">{{item.classifyName}}</view>
					<view class="tadyOrder-right-b" @tap.stop="bindGps(item.latitude,item.longitude,item.detailsAddress)">
						<u-icon name="map-fill" color="#0175FE" size="28"></u-icon>
						<span style="margin-left: 5rpx;">{{item.city}}{{item.district}}{{item.detailsAddress}}</span>
					</view>
				</view>
			</view>
			<empty v-if="orderlist.length==0" content="暂无订单"></empty>
		</view>
		<!-- 开始时间 -->
		<u-picker v-model="startshow" mode="time" :params="paramsStart" @confirm="startData"></u-picker>
		<!-- 结束时间 -->
		<u-picker v-model="endshow" mode="time" :params="paramsEnd" @confirm="endData"></u-picker>

		<u-popup v-model="popusAuthorization" :showBg="false" mode="center" >
			<view class="contentview">
				<view class="title">隐私保护指引</view>
				<view class="des" @click="openPrivacyContract">
					在使用当前小程序服务之前，请仔细阅读<text
						style="color: #557EFD;">{{privacyContractName}}</text>。如你同意{{privacyContractName}}，请点击“同意”开始使用。
				</view>
				<view class="btns">
					<button class="item reject" @click="exitMiniProgram">拒绝</button>
					<button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization"
						@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				privacyContractName: '',
				popusAuthorization: false,

				avatar: '../../static/logo.png',
				isLogin: true,
				userName: '匿名',
				renzheng: 0,
				startshow: false,
				endshow: false,
				paramsStart: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				paramsEnd: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				startTime: '',
				endTime: '',
				orderlist: [],
				sumOrdersMoney: 0, //总收益
				sumOrdersCount: 0, //总销量
				sumOrdersScore: 0, //用户评价数
				ordersMoney: 0, //订单收入
				ordersCount: 0, //总订单数
				refundMoney: 0, //退款金额
				userBrowseCount: 0, //访客人数
				// countOrderIng: 0, //待接单
				ordersUnderwayCount: 0, //待完成
				ordersAccomplishCount: 0, //已完成
				commentCount: 0, //已评价
				shangCount: 0, //上架中
				xiaCount: 0, //下架中
				page: 1,
				limit: 10,
				longitude: '',
				latitude: '',
				isTrue: true,
				showModal: true,
				userId: '',
				arr: [],
				city: '',
				isCashDeposit: 0,
				geRen: 0,
				Qe: 0,
				classify: 1,
				counts: 0,
				money: 0,
				isAuthentication: '',
				order: [{
					id: 1,
					name: '服务订单'
				}, {
					id: 2,
					name: '任务订单'
				}],
				orderIndex: 0,
				count: 0,
				XCXIsSelect: '否'
			}
		},
		onLoad() {
			this.userId = uni.getStorageSync('userId')
			// #ifdef MP-WEIXIN
			try{
				wx.getPrivacySetting({
					success: res => {
						console.log("是否需要授权：", res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
						if (res.needAuthorization) {
							this.privacyContractName = res.privacyContractName;
							// this.$refs.popusAuthorization.open();
							this.popusAuthorization = true
						}
					},
					fail: () => {},
					complete: () => {},
				})
			}catch(e){
				//TODO handle the exception
			}
			
			// #endif
			this.XCXIsSelect = uni.getStorageSync('XCXIsSelect')
			this.classify = uni.getStorageSync("classify") ? uni.getStorageSync("classify") : '1'
			// this.status = uni.getStorageSync('status')
			this.$Request.getT('/app/common/type/235').then(res => { //新订单通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arr.push(res.data.value)
					}
				}
			})
			this.$Request.getT('/app/common/type/311').then(res => { //商家私聊消息通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arr.push(res.data.value)
					}
				}
				
			})
			// 商家端订单状态通知	623
			this.$Request.getT('/app/common/type/623').then(res => { //商家端订单状态通知
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arr.push(res.data.value)
					}
				}
				
			})
			
		},
		onShow() {
			this.userId = uni.getStorageSync('userId')
			this.Qe = uni.getStorageSync("Qe")
			// this.geRen = uni.getStorageSync("geRen")
			if (this.Qe == 2) {
				this.renzheng = false
			} else {
				this.renzheng = true
			}
			this.isCashDeposit = uni.getStorageSync('isCashDeposit')
			if (this.userId) {
				this.isLogin = false
				this.getUserInfo()
				// this.getRenZheng()
				this.getRenZhengs()
				this.getFb()
				this.getfuOrder()
				this.getorder()
				this.getTodayOrder()
				// #ifdef MP-WEIXIN
				//订阅
				if (this.showModal) {
					this.openMsg()
				}
				// #endif
			} else {
				this.isLogin = true
				this.userName = '匿名'
				this.browse = 0
				this.fans = 0
				this.follow = 0
				this.visitor = 0
				this.avatar = '../../static/logo.png'
				this.sumOrdersMoney = 0 //总收益
				this.shangCount = 0 //上架中
				this.xiaCount = 0 //下架中
				this.sumOrdersCount = 0 //总销量
				this.sumOrdersScore = 0 //用户评价
				this.ordersMoney = 0 //订单收入
				this.ordersCount = 0 //总订单数
				this.refundMoney = 0 //退款金额
				this.userBrowseCount = 0 //访客人数
				this.orderlist = []
				this.ordersAccomplishCount = 0 //已完成
				this.commentCount = 0 //已评价
				this.ordersUnderwayCount = 0 //待完成

				this.counts = 0 //已评价
				this.money = 0 //待完成
			}
			let that = this
			setInterval(function() {
				that.getfuOrder()
			}, 10000)

		},
		methods: {
			// 一键导航
			bindGps(latitude, longitude, name) {
				uni.openLocation({
					latitude: latitude - 0, //要去的纬度-地址       
					longitude: longitude - 0, //要去的经度-地址
					name: name, //地址名称
					address: name, //详细地址名称
					success: function() {
						console.log('导航成功');
					},
					fail: function(error) {
						console.log(error)
					}
				});
			},
			// 打开隐私协议页面
			openPrivacyContract() {
				let that = this;
				wx.openPrivacyContract({
					fail: () => {
						that.$queue.showToast('遇到错误无法打开！');
					}
				})
			},
			// 拒绝隐私协议
			exitMiniProgram() {
				// 直接退出小程序
				wx.exitMiniProgram()
			},
			// 同意隐私协议
			handleAgreePrivacyAuthorization() {
				// this.$refs.popusAuthorization.close();
				this.popusAuthorization = false
			},
			orderChange(index) {
				this.orderIndex = index
				this.page = 1
				this.orderlist = []
				this.getTodayOrder()
			},
			// 获取新服务订单消息提醒
			getfuOrder() {
				this.$Request.getT("/app/orders/getOrdersRemind").then(res => {
					if (res.code == 0) {
						if (res.data == 1) {
							this.aplayAudio()
						}
					}
				});
			},
			aplayAudio() {
				// console.log('语音提示')
				const innerAudioContext = uni.createInnerAudioContext();
				innerAudioContext.autoplay = true;
				// innerAudioContext.src =
				// 	'https://pw.xianmxkj.com/file/uploadPath/2022/01/19/0753211f78d718d44ee6372e33eae9ee.mp3';
				innerAudioContext.src =
					'https://pw.xianmxkj.com/file/uploadPath/2022/03/25/c9bc6a731dec661f06d4122dfcb3141c.mp3';

				innerAudioContext.onPlay(() => {
					console.log('开始播放');
				});
				innerAudioContext.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
				});
			},
			getcity() {
				let that = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						that.latitude = res.latitude
						that.longitude = res.longitude
						that.getcitys()
					}
				});
			},
			getcitys() {
				this.$Request.get('/app/Login/selectCity?lat=' + this.latitude + '&lng=' + this.longitude).then(res => {
					if (res.code == 0) {
						this.city = res.data.city ? res.data.city : '未知'
					}
				});
			},
			getorder() {
				this.$Request.get("/app/orders/selectCompanyStatistics").then(res => {
					if (res.code == 0) {
						this.counts = res.data.counts
						this.money = res.data.money
					}
				});
			},
			//获取技师的信息
			getArtificer() {
				this.$Request.getT("/app/artificer/selectArtificer").then(res => {
					if (res.code == 0) {
						// uni.setStorageSync("status", res.data.status)

						if (res.data.status == 1) {
							this.isTrue = true
						} else if (res.data.status == 2) {
							this.isTrue = false
						}
						uni.setStorageSync('artificerId', res.data.artificerId)
					}
				});
			},
			//获取用户发布
			getFb() {
				let data = {
					startTime: this.startTime,
					endTime: this.endTime,
				}
				this.$Request.get("/app/orderTaking/selectShopData", data).then(res => {
					uni.stopPullDownRefresh();
					if (res.code == 0) {
						this.sumOrdersMoney = res.data.sumOrdersMoney //总收益
						this.shangCount = res.data.shangCount //上架中
						this.xiaCount = res.data.xiaCount //下架中
						this.sumOrdersCount = res.data.sumOrdersCount //总销量
						this.sumOrdersScore = res.data.sumOrdersScore //用户评价
						this.ordersMoney = res.data.ordersMoney //订单收入
						this.ordersCount = res.data.ordersCount //总订单数
						this.refundMoney = res.data.refundMoney //退款金额
						this.userBrowseCount = res.data.userBrowseCount //访客人数
						// this.countOrderIng = res.data.countOrderIng //进行中
						this.ordersAccomplishCount = res.data.ordersAccomplishCount //已完成
						this.commentCount = res.data.commentCount //已评价
						this.ordersUnderwayCount = res.data.ordersUnderwayCount //待完成
					}
				})
			},
			//获取今日订单
			getTodayOrder() {
				let userId = uni.getStorageSync('userId')
				let myDate = new Date()
				let myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
				let myMonth = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
				let myToday = myDate.getDate(); //获取当前日(1-31)
				let startTime = myYear + '-' + myMonth + '-' + myToday
				// console.log(startTime, '当前时间')
				if (userId) {
					if (this.orderIndex == 0) {
						let data = {
							page: this.page,
							limit: this.limit,
							startTime: startTime,
							status: 5
						}
						this.$Request.get("/app/orders/selectMyTakeOrders", data).then(res => {
							if (res.code == 0) {
								this.count = res.data.totalCount
								if (this.page == 1) {
									for (var i = 0; i < res.data.list.length; i++) {
										if (res.data.list[i].startTime) {
											res.data.list[i].startTime = res.data.list[i].startTime.substring(10,
												24)
										}
									}
									this.orderlist = res.data.list
								} else {
									for (var i = 0; i < res.data.list.length; i++) {
										if (res.data.list[i].startTime) {
											res.data.list[i].startTime = res.data.list[i].startTime.substring(10,
												24)
										}
									}
									this.orderlist = [...this.orderlist, ...res.data.list]

								}

							}
							//请求结束后停止下拉
							uni.stopPullDownRefresh()
						})
					} else if (this.orderIndex == 1) {
						let data = {
							page: this.page,
							limit: this.limit,
							deliveryTime: startTime,
							status: 6
						}
						this.$Request.get("/app/help/selectRunHelpOrder", data).then(res => {
							if (res.code == 0) {
								if (this.page == 1) {
									this.orderlist = res.data.list
									for (var i = 0; i < this.orderlist.length; i++) {
										this.orderlist[i].deliveryTime = this.orderlist[i].deliveryTime.substring(
											5,
											18)
									}
								} else {
									this.orderlist = [...this.orderlist, ...res.data.list]
									for (var i = 0; i < this.orderlist.length; i++) {
										this.orderlist[i].deliveryTime = this.orderlist[i].deliveryTime.substring(
											5,
											18)
									}
								}
								this.count = res.data.totalCount
							}
							//请求结束后停止下拉
							uni.stopPullDownRefresh()
						})
					}
				}

			},
			goDetail(index) {
				if (uni.getStorageSync('sendMsg')) {
					console.log('授权+1')
					wx.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							console.log(JSON.stringify(re), 111111111111)
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								// console.log(re)
							}
						},
						fail: (res) => {
							// console.log(res)
						}
					})
				}
				let userId = uni.getStorageSync('userId')
				if (userId) {
					if (index == 1) {
						uni.switchTab({
							url: '/pages/my/index'
						})
					} else if (index == 2) {
						if (this.orderIndex == 0) {
							uni.navigateTo({
								url: '/my/order/index'
							})
						} else if (this.orderIndex == 1) {
							uni.navigateTo({
								url: '/my/takeOrder/index'
							})
						}

					} else if (index == 3) {
						uni.navigateTo({
							url: '/work/statistics/statistics?companyId=' + userId
						})
					} else if (index == 4) {
						uni.navigateTo({
							url: '/my/publish/index'
						});
					}
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}

			},
			goDetails(item) {
				if (uni.getStorageSync('sendMsg')) {
					console.log('授权+1')
					wx.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							console.log(JSON.stringify(re), 111111111111)
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								// console.log(re)
							}
						},
						fail: (res) => {
							// console.log(res)
						}
					})
				}
				let userId = uni.getStorageSync('userId')
				if (userId) {
					if (this.orderIndex == 0) {
						uni.navigateTo({
							url: '/my/order/pay?id=' + item.ordersId
						})
					} else if (this.orderIndex == 1) {
						uni.navigateTo({
							url: '/my/takeOrder/takeDetail?id=' + item.helpOrderId
						})
					}
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			
			},
			bindFb() {
				if (uni.getStorageSync('sendMsg')) {
					console.log('授权+1')
					wx.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							console.log(JSON.stringify(re), 111111111111)
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								// console.log(re)
							}
						},
						fail: (res) => {
							// console.log(res)
						}
					})
				}
				let userId = uni.getStorageSync('userId')
				this.classify = uni.getStorageSync('classify')
				if (userId) {
					if (this.Qe == 2) {
						uni.navigateTo({
							url: '/my/publish/index'
						})
					} else if (this.Qe == 1) {
						uni.showModal({
							title: '提示',
							content: '实名认证审核中,请稍等',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									// uni.navigateTo({
									// 	url: '/my/renzheng/index'
									// })
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					} else {
						uni.showModal({
							title: '提示',
							content: '您还未实名认证,请先认证',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									uni.navigateTo({
										url: '/my/renzheng/index?classify=' + this.classify
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					}

				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			//时间弹框开关
			bindData(index) {
				if (uni.getStorageSync('sendMsg')) {
					console.log('授权+1')
					wx.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							console.log(JSON.stringify(re), 111111111111)
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								// console.log(re)
							}
						},
						fail: (res) => {
							// console.log(res)
						}
					})
				}
				// console.log(index, 1111)
				if (index == 1) {
					this.startshow = true
				} else if (index == 2) {
					this.endshow = true

				}
			},
			//开始时间
			startData(e) {
				this.startTime = e.year + '-' + e.month + '-' + e.day
			},
			// 结束时间
			endData(e) {
				this.endTime = e.year + '-' + e.month + '-' + e.day
				this.getFb()
			},
			goNav(e, name) {
				console.log(e)
				if (uni.getStorageSync('sendMsg')) {

					wx.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								// console.log(re)
							}
						},
						fail: (res) => {
							// console.log(res)
						}
					})
				}
				if (this.userId) {
					if (this.Qe == 2) {
						uni.navigateTo({
							url: e
						})
					} else if (this.Qe == 1) {
						uni.showModal({
							title: '提示',
							content: '实名认证审核中,请稍等',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									// uni.navigateTo({
									// 	url: '/my/renzheng/index'
									// })
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					} else {
						uni.showModal({
							title: '提示',
							content: '您还未实名认证,请先认证',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									uni.navigateTo({
										url: '/my/renzheng/index?classify=' + this.classify
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					}

				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.userName = res.data.userName
						this.invitationCode = res.data.invitationCode
						this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
						this.isAuthentication = res.data.isAuthentication
						this.isCashDeposit = res.data.isCashDeposit
						uni.setStorageSync('avatar', res.data.avatar)
						uni.setStorageSync('invitationCode', res.data.invitationCode)
						// uni.setStorageSync('zhiFuBao', res.data.zhiFuBao)
						// uni.setStorageSync('zhiFuBaoName', res.data.zhiFuBaoName)
					}
				});
			},
			goLogin(e) {
				uni.navigateTo({
					url: e
				})
			},
			// 开启订阅消息
			openMsg() {
				console.log('订阅消息')
				var that = this
				uni.getSetting({
					withSubscriptions: true, //是否获取用户订阅消息的订阅状态，默认false不返回
					success(ret) {
						console.log(ret.subscriptionsSetting, '------------------')
						// if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
						if (ret.subscriptionsSetting.itemSettings) {
							uni.setStorageSync('sendMsg', true)
							uni.openSetting({ // 打开设置页 
								success(rea) {
									console.log(rea.authSetting)
								}
							});
						} else { // 用户没有点击“总是保持以上，不再询问”则每次都会调起订阅消息
							console.log(99999)
							uni.setStorageSync('sendMsg', false)
							uni.showModal({
								title: '提示',
								content: '为了更好的体验,请绑定消息推送',
								confirmText: '确定',
								cancelText: '取消',
								success: function(res) {
									if (res.confirm) {
										wx.requestSubscribeMessage({
											tmplIds: that.arr,
											success(re) {
												console.log(JSON.stringify(re),
													'++++++++++++++')
												var datas = JSON.stringify(re);
												if (datas.indexOf("accept") != -1) {
													console.log(re)
													// uni.setStorageSync('sendMsg', true)
												}
											},
											fail: (res) => {
												console.log(res)
											}
										})
										// uni.setStorageSync('sendMsg', true)
										console.log('确认')
										that.showModal = false
									} else if (res.cancel) {
										console.log('取消')
										// uni.setStorageSync('sendMsg', false)
										that.showModal = true
									}
								}
							})
						}
					}
				})
			},
			// 个人认证数据
			// getRenZheng() {
			// 	let classify
			// 	this.$Request.get("/app/userCertification/queryInsert?classify=" + 1).then(res => {
			// 		console.log(res)
			// 		if (res.code == 0) {
			// 			if (res.data == null) {
			// 				this.geRen = 0
			// 				uni.setStorageSync("geRen", this.geRen)
			// 			} else if (res.data.status == 0) {
			// 				this.geRen = 1
			// 				uni.setStorageSync("geRen", this.geRen)
			// 			} else if (res.data.status == 1) {
			// 				this.geRen = 2
			// 				uni.setStorageSync("geRen", this.geRen)
			// 			} else if (res.data.status == 2) {
			// 				this.geRen = 3
			// 				uni.setStorageSync("geRen", this.geRen)
			// 			}
			// 		}
			// 	});
			// },
			// 企业认证数据
			getRenZhengs() {
				let classify
				this.$Request.get("/app/userCertification/queryInsert?classify=" + 2).then(res => {
					console.log(res)
					if (res.code == 0) {
						if (res.data == null) { //未实名
							this.Qe = 0
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 0) { //审核中
							this.Qe = 1
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 1) { //已实名
							this.Qe = 2
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 2) { //已拒绝
							this.Qe = 3
							uni.setStorageSync("Qe", this.Qe)
						}
					}
				});
			},
		},
		onReachBottom: function() {
			if (this.count == this.orderlist.length) {
				uni.showToast({
					title: '已经到底了~',
					icon: 'none'
				})
				return
			} else {
				this.page = this.page + 1;
				this.getTodayOrder()
			}
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getTodayOrder()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}



	.bg {
		background-color: #FFFFFF;
	}

	.box {
		width: 690upx;
		margin: 0 auto;
		height: 120rpx;
		background: #557EFD;
		border-radius: 16upx 16upx 0px 0px;
		color: #FFFFFF;
		padding: 0upx 30upx;
		margin-top: 20upx;
	}

	.orderbox {
		width: 690upx;
		margin: 0 auto;
		height: 153upx;
		background: #FAFAFA;
		border-radius: 16upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		text-align: center;
		padding: 0upx 30upx;
	}

	.page-box {
		position: relative;
		left: 0;
		height: 50vh;
		background-color: #FFFFFF;
	}

	.orderbox1 {
		// background: #a9beff;
		padding: 20upx 0;
		color: #333;

	}

	.active {
		background: #F2F5FF;
		color: #557EFD;
	}

	.tadyOrder {
		width: 100%;
		// height: 140rpx;
		border-radius: 16rpx;
		background-color: #FAFAFA;
		margin-top: 30rpx;
		padding-bottom: 25rpx;
		display: flex;
		align-items: center;

		.tadyOrder-left {
			width: 207rpx;
			height: 108rpx;
			border-right: 1rpx solid #E6E6E6;
			text-align: center;

			.tadyOrder-left-t {
				color: #333333;
				font-size: 24rpx;
			}

			.tadyOrder-left-b {
				color: #0175FE;
				font-size: 28rpx;
				margin-top: 15rpx;

			}
		}

		.tadyOrder-right {
			width: calc(100% - 217rpx);
			height: 100%;
			// display: flex;
			// flex-wrap: wrap;
			// align-items: center;

			align-content: flex-start;

			.tadyOrder-right-t {
				color: #1E1F31;
				font-size: 28rpx;
				font-weight: bold;
				padding-left: 40rpx;
			}

			.tadyOrder-right-b {
				display: flex;
				color: #333333;
				font-size: 24rpx;
				margin-top: 10rpx;
				padding-left: 10rpx;
			}
		}
	}
	
	// 隐私协议i样式
	.privacy {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background: rgba(0, 0, 0, .5);
		z-index: 9999999;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.contentview {
		width: 632rpx;
		padding: 48rpx;
		box-sizing: border-box;
		background: #fff;
		border-radius: 16rpx;
	}
	
	.contentview .title {
		text-align: center;
		color: #333;
		font-weight: bold;
		font-size: 32rpx;
	}
	
	.contentview .des {
		font-size: 26rpx;
		color: #666;
		margin-top: 40rpx;
		text-align: justify;
		line-height: 1.6;
	}
	
	.contentview .des .link {
		color: #557EFD;
		text-decoration: underline;
	}
	
	button::after {
		border: none;
	}
	
	.btns {
		margin-top: 48rpx;
		display: flex;
	}
	
	.btns .item {
		justify-content: space-between;
		width: 244rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 16rpx;
		box-sizing: border-box;
		border: none;
	}
	
	.btns .reject {
		background: #f4f4f5;
		color: #909399;
	}
	
	.btns .agree {
		background: #557EFD;
		color: #fff;
	}
</style>